package com.wanmait.movie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.movie.entity.MovieType;
import com.wanmait.movie.mapper.MovieTypeMapper;
import com.wanmait.movie.service.MovieTypeService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class MovieTypeServiceImpl extends ServiceImpl<MovieTypeMapper, MovieType> implements MovieTypeService {
    @Resource
    private MovieTypeMapper movieTypeMapper;

    @Override
    @Cacheable(value = "commonCache",unless = "#result == null")
    public List<MovieType> getMovieTypeList(String keyword) {
        LambdaQueryWrapper<MovieType> queryWrapper = new LambdaQueryWrapper<>();
        if (keyword != null){
            queryWrapper.like(MovieType::getMovieTypeName,keyword).or().like(MovieType::getMovieTypeDescribe,keyword);
        }
        List<MovieType> movieTypeList=movieTypeMapper.selectList(queryWrapper);
        return movieTypeList;
    }

}
